package whf.framework.tools.generator;

import whf.framework.exception.CreateException;
import whf.framework.exception.DAOException;
import whf.framework.exception.NotFoundException;
import whf.framework.exception.RemoveException;
import whf.framework.exception.UpdateException;
import whf.framework.service.Service;
import whf.framework.util.Output;

/**
 * @author wanghaifeng
 *
 */
public class ServiceGenerator extends AbstractGenerator{
	private String packageName;

	private String className;

	private String boClassName;

	public ServiceGenerator(String packageName, String className, String boName) {
		this.packageName = packageName;
		this.className = className;
		this.boClassName = boName;
	}

	protected void gen() {
		super.setPackageName(this.packageName+".service");
		super.addImport(this.packageName+".entity.*");
		super.addImport(DAOException.class.getPackage().getName()+".*");
		super.setInterface(true);
		super.setClassName(this.className);
		super.setSuperClassName(Service.class.getName());
		String boParamName = boClassName.substring(0,1).toLowerCase() + boClassName.substring(1);
		super.addAbstractMethod("create","void",new String[]{this.boClassName},
				new String[] { boParamName },new Class[] { CreateException.class });
		super.addAbstractMethod("update","void",new String[]{this.boClassName},
				new String[] { boParamName },new Class[] { UpdateException.class });
		super.addAbstractMethod("remove","void",new String[]{this.boClassName},
				new String[] { boParamName },new Class[] { RemoveException.class });
		super.addAbstractMethod("remove","void",new String[]{"long"},
				new String[] { "id" },new Class[] { RemoveException.class });
		super.addAbstractMethod("remove","void",new String[]{"long[]"},
				new String[] { "ids" },new Class[] { RemoveException.class });
		super.addAbstractMethod("findByPrimaryKey",this.boClassName,new String[]{"long"},
				new String[] { "id" },new Class[] { NotFoundException.class });
		
	}

	public static void main(String args[]) throws Exception {
		Output out = new Output(System.out);
		ServiceGenerator gen = new ServiceGenerator("com.hh.shop", "IShopDAO",
				"ShopDO");
		gen.output(out);
	}

}
